# Maintainer: Zach Bacon <11doctorwhocanada@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=midori
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.5.11
pkgrel=1
pkgdesc="midori web browser (mingw-w64)"
arch=('any')
url='http://www.midori-browser.org/'
license=('LGPL2.1')
options=('debug' '!strip')
depends=("${MINGW_PACKAGE_PREFIX}-vala"
         "${MINGW_PACKAGE_PREFIX}-webkitgtk3"
         "${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-gstreamer"
         "${MINGW_PACKAGE_PREFIX}-cmake"
         "${MINGW_PACKAGE_PREFIX}-pkg-config")
optdepends=("${MINGW_PACKAGE_PREFIX}-gst-plugins-good: HTML5 OGG videos support"
            "${MINGW_PACKAGE_PREFIX}-gst-plugins-base: HTML5 H264 and WebM videos support"
            "${MINGW_PACKAGE_PREFIX}-gst-libav: HTML5 H264 videos support"
            "${MINGW_PACKAGE_PREFIX}-aria2: download utility"
            "${MINGW_PACKAGE_PREFIX}-drmingw: debugging support")
source=("http://www.midori-browser.org/downloads/${_realname}_${pkgver}_all_.tar.bz2"
        "0001-ValaPrecompile-abs-path-regex-win-friendly.patch")
sha256sums=('96191a96be71144ae848a409fae5a1d6d52a00e583f33122081f47ead9c49c3d'
            'bb36af38d2d113e857407451d4dff3dcc38d26a9289a86e45a8f4e99f7da14d1')

prepare() {
  cd $srcdir/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-ValaPrecompile-abs-path-regex-win-friendly.patch
}

build() {
  cd "$srcdir"/${_realname}-${pkgver}
  [ -d "${srcdir}"/build-${CARCH} ] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  local -a extra_config

  if check_option "debug" "y"; then
    extra_config+=( -DCMAKE_BUILD_TYPE=Debug )
  else
    extra_config+=( -DCMAKE_BUILD_TYPE=Release )
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DUSE_GTK3=1 \
    -DUSE_ZEITGEIST=0 \
    "${extra_config[@]}" \
    ../${_realname}-${pkgver}
  make
}

# check() {
#   cd "${srcdir}"/build-${CARCH}
#   make check
# }

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"
}
